package practise.alogrithm.gotoSiliconValley.array;

/**
 * Giving a array, for a given k, rotate the array for that number.
 */
public class RotateArray {
    public int[] rotateArray(int[] array,int k){
        reverse(array,0,array.length-1);
        reverse(array,0,k-1);
        reverse(array,k,array.length-1);
        return array;

    }
    private void reverse(int[] array,int start, int end){
        while (start<end){
            int temp = array[start];
            array[start]=array[end];
            array[end]=temp;
            start++;
            end--;
        }
    }

}
